<template>
	<div class="flex-start-center">
		<el-popover v-model="showPopoverState" trigger="click" title="生产通知单" width="740">
			<!--<div class="margin-bottom-4">
				<el-button size="mini" icon="el-icon-plus" @click="onPlanShareBtn">新增</el-button>
			</div>-->
			<jk-table border :data="tableData" size="mini" :height="240">
				<vxe-column title="工序" align="center" field="processName" :width="70"></vxe-column>
				<vxe-column title="批号" align="left" field="batchCode" :min-width="160"></vxe-column>
				<vxe-column :width="140" align="left" field="code" title="单据编号">
					<!--<template slot-scope="scope">
						<div class="flex-center">
							<el-button class="item-gap" size="mini" type="text" @click="onEditBtn(scope.row)">
								<span>{{ scope.row.code }}</span>
								<span class="el-icon-edit"></span>
							</el-button>
						</div>
					</template>-->
				</vxe-column>
				<vxe-column title="排产数量" align="right" field="productionQty" :width="90"></vxe-column>
				<!--<vxe-column title="排产机台数" align="right" field="machineQty" :width="80"></vxe-column>-->
				<vxe-column title="区域" align="left" field="workshopName" :width="90"></vxe-column>
				<vxe-column title="状态" align="left" field="openingState" :width="80">
					<template slot-scope="scope">
						<jk-state-bar :state="scope.row.auditState" :state-list="noticeStateList"></jk-state-bar>
					</template>
				</vxe-column>
				<!--<vxe-column title="日供货量" align="right" field="productionDailyQty" :width="80"></vxe-column>-->
				<!--<vxe-column width="174" align="center" field="version" title="计划日期">
                    <template slot-scope="scope">
                        <div class="flex-center">
                            {{ `${scope.row.planStartDate}~${scope.row.planFinishDate}` }}
                        </div>
                    </template>
                </vxe-column>-->
			</jk-table>
			<div v-show="ruleForm.id" slot="reference">
				<el-button size="mini" icon="el-icon-s-order" class="">
					<span>生产通知单：</span>
					<span style="font-weight: 700; font-size: 13px;">{{ tableData.length }}</span>
					<span> 个</span>
				</el-button>
			</div>
		</el-popover>
		<!--<el-button v-show="ruleForm.id && ruleForm.serviceState !== 3" size="mini" icon="el-icon-plus" @click="onPlanShareBtn"></el-button>-->
		<share-plan-dialog
			:data-item="ruleForm"
			:data-id="ruleForm.id"
			:dialog-state="sharePlanDialogState"
			@on-visible-change="onVisibleChangeOfSharePlanDialogState"
			@on-finish="onFinish"
		></share-plan-dialog>
		<notice-order-dialog
			page-type="edit"
			:data-id="dataId"
			:dialog-state="noticeOrderDialogState"
			@on-visible-change="onVisibleChangeOfNoticeOrderDialogState"
		></notice-order-dialog>
	</div>
</template>
<script>
    import { productionProcessPrdNoticePage } from '../../../../api/production/xsNotice';
    import sharePlanDialog from './share-plan-dialog';
    import { noticeStateList } from '../../../../utils/jk/status-option-list';
    import noticeOrderDialog from './notice-order-dialog';
    export default {
        components: {
            noticeOrderDialog,
            sharePlanDialog
        },
        props: {
            ruleForm: {
                type: Object,
                default() {
                    return {};
                }
            }
        },
        data() {
            return {
                dataId: null,
                noticeOrderDialogState: false,
                noticeStateList: noticeStateList,
                sharePlanDialogState: false,
                showPopoverState: false,
                tableData: []
            };
        },
        methods: {
            onVisibleChangeOfNoticeOrderDialogState(e) {
                this.noticeOrderDialogState = e;
            },
            onFinish() {
                this.getListRequest();
            },
            onVisibleChangeOfSharePlanDialogState(e) {
                this.sharePlanDialogState = e;
            },
            onPlanShareBtn() {
                this.sharePlanDialogState = true;
            },
            onEditBtn(row) {
                this.dataId = row.id;
                this.noticeOrderDialogState = true;
                /* this.$toOtherRouter({
                    name: 'editProductionNoticeOrder',
                    query: {
                        id: row.id
                    }
                });*/
            },
            getListRequest() {
                if (!this.ruleForm.code) return;
                return productionProcessPrdNoticePage({ productOrderId: this.ruleForm.id }).then(res => {
                    if (res.data.status === 200) {
                        this.tableData = res.data.res;
                    }
                });
            }
        },
        watch: {
            showPopoverState(newVal) {
                if (newVal) {
                    this.getListRequest();
                }
            }
        }
    };
</script>
